//
//  PopoverPresentationController.swift
//  sinaWeibo
//
//  Created by 张国梁 on 16/4/5.
//  Copyright © 2016年 CoderGL. All rights reserved.
//

import UIKit

@available(iOS 8.0, *)
class PopoverPresentationController: UIPresentationController {
    

    
    override func containerViewWillLayoutSubviews() {
        super.containerViewWillLayoutSubviews()
        
        presentedView()?.frame.size = CGSize(width: 200, height: 300)
        presentedView()?.center.x = (containerView?.center.x)!;
        presentedView()?.frame.origin.y = 56
        
        
        containerView?.insertSubview(maskView, belowSubview: presentedView()!)
    }
    
    private lazy var maskView : UIView = {
        let maskView = UIView()
        maskView.frame = UIScreen.mainScreen().bounds;
        maskView.backgroundColor = UIColor(white: 0, alpha: 0.2)
        
        let tapGesture = UITapGestureRecognizer(target: self, action: #selector(PopoverPresentationController.dismiss))
        maskView.addGestureRecognizer(tapGesture)
        return maskView
    }()
    
    func dismiss() -> Void {
        presentedViewController.dismissViewControllerAnimated(true, completion: nil)
    }
    
}
